import 'database_manager.dart';

void main() async {
  final db = DatabaseManager();
  
  try {
    // 连接数据库
    await db.connect();
    
    // 添加记录
    await db.addRecord('张三', 'Hello!');
    await db.addRecord('李四', 'Hi there!');
    
    // 获取所有记录
    print('\n所有记录：');
    var records = await db.getAllRecords();
    for (var record in records) {
      print('ID: ${record['id']}, 名称: ${record['name']}, 消息: ${record['message']}');
    }
    
    // 获取单条记录
    const recordId = 1;
    var record = await db.getRecordById(recordId);
    if (record != null) {
      print('\n获取ID为$recordId的记录：');
      print('ID: ${record['id']}, 名称: ${record['name']}, 消息: ${record['message']}');
    }
    
    // 更新记录
    await db.updateRecord(1, name: '张三(已更新)', message: 'Updated message!');
    
    // 删除记录
    await db.deleteRecord(2);
    
    // 再次获取所有记录
    print('\n更新后的所有记录：');
    records = await db.getAllRecords();
    for (var record in records) {
      print('ID: ${record['id']}, 名称: ${record['name']}, 消息: ${record['message']}');
    }
  } catch (e) {
    print('操作失败: ${e.toString()}');
  } finally {
    await db.close();
  }
}
